 #include <sql_pool.h>
 oal_bool sql_pool::Init(string host, string user, string passwd, string database ,oal_uint16 sql_num)
 {
    //oal_print("init\n!!");
    g_ast_connect_num = sql_num;
    g_ast_sqlconnect  = (Mysql_connect_entry *)malloc(g_ast_connect_num*sizeof(Mysql_connect_entry));
    if(g_ast_sqlconnect == NULL)
    {
        return false;
    }
   // oal_print("mysql 1111111\n!!");
    for(oal_uint16 i = 0;i < g_ast_connect_num; i++)
    {
        g_ast_sqlconnect[i].sqlconnect =  new mysqlconnect();
        if(!g_ast_sqlconnect[i].sqlconnect)
        {
            return false;
        }
        if(!g_ast_sqlconnect[i].sqlconnect->Init(host, user, passwd,database))
        {
            oal_print("mysql 22222\n!!");
            return false;
        }
        // oal_print("mysql 33333\n!!");
    }
    for(oal_uint16 i = 0;i < g_ast_connect_num - 1; i++)
    {
        g_ast_sqlconnect[i].next = &g_ast_sqlconnect[i+1];
    }
    g_ast_sqlconnect[g_ast_connect_num - 1].next = oal_ptr_null;
    connect_head = g_ast_sqlconnect;
    connect_tail = g_ast_sqlconnect + g_ast_connect_num - 1;
     oal_print("mysql list ok\n!!");
    return true;
 }
mysqlconnect* sql_pool::get_connect()
{
    Mysql_connect_entry *temp_sqlconnect;
    //oal_print("mysql lllll\n!!");
    pthread_spin_lock(&connect_get_lock); 
    if(connect_head == connect_tail)
    {
        return NULL;
    }
    temp_sqlconnect = connect_head;
    //oal_print("mysql zzzz\n!!");
    connect_head = connect_head->next;
    pthread_spin_unlock(&connect_get_lock); 
    //oal_print("mysql yyy\n!!");
    temp_sqlconnect->next = oal_ptr_null;
    //oal_print("mysql nnn\n!!");
    return temp_sqlconnect->sqlconnect;
}
oal_void  sql_pool::free_connect(mysqlconnect *used_connect)
{
    struct mysql_connect_entry  *entry = (struct mysql_connect_entry  *)used_connect;
    pthread_spin_lock(&connect_put_lock);
    connect_tail->next = entry;
    connect_tail       = entry;
    pthread_spin_unlock(&connect_put_lock); 
    entry->next        = oal_ptr_null;
}